package com.mattidroid.spiegel;

import android.app.Application;
import android.content.SharedPreferences;
import android.util.Log;

public class GlobalClass extends Application {
 
	
	// Store global selected Locale
	public int overrideLocale = 0;
	
	// returns string for position of locale
	String isLocaleString (int _LocaleNumber) {
		
		switch (_LocaleNumber) {
			case 0: return ""; 
			case 1: return "de"; 
			case 2: return "en";
			default: return "";
		}
	}
	
	// Store current tab in GlobalClass
	public int currentGlobalTab;
	
	// Debug Variables (dynamic via more settings)
	static boolean isDebug = false;
	static boolean isDeepDebug = false;	
	
	int _isDebugLevel_1 = 0;
	int _isDebugLevel_2 = 0;
	
	static final int LANG_GER = 0;
	static final int LANG_ENG = 1;	

	int _selectLanguage = LANG_GER; // 0 = DE, 1 = EN
	
	static final int TAB_ON = 1;	
	static final int TAB_OFF = 0;	

	int _isStartTab = TAB_ON;
	int _isWirtschaftTab = TAB_ON;
	int _isPolitikTab = TAB_ON;
	int _isSportTab = TAB_ON;	
	int _isNetzweltTab = TAB_ON;
	int _isWissenschaftTab = TAB_ON;		
	int _isPanoramaTab = TAB_ON;	
	int _isTickerTab = TAB_ON;
	int _isRubrikenTab = TAB_ON;
	
	int _isSwipeOn = 1;

	// for pref storage
	public static final String PREFS_NAME = "Spiegel.prefs";
	
	public void getStoredSettings () {
		
	    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
	    
	    _selectLanguage = settings.getInt("_setLanguage", LANG_GER);   
	    _isStartTab = settings.getInt("_isStartTab", TAB_ON);
	    _isWirtschaftTab = settings.getInt("_isWirtschaftTab", TAB_ON);
	    _isPolitikTab = settings.getInt("_isPolitikTab", TAB_ON);	   
	    _isSportTab = settings.getInt("_isSportTab", TAB_ON);
	    _isNetzweltTab = settings.getInt("_isNetzweltTab", TAB_ON);
	    _isWissenschaftTab = settings.getInt("_isWissenschaftTab", TAB_ON);	   
		_isPanoramaTab = settings.getInt("_isPanoramaTab", TAB_ON);	
		_isTickerTab = settings.getInt("_isTickerTab", TAB_ON);	
		_isRubrikenTab = settings.getInt("_isRubrikenTab", TAB_ON);	
		
		_isSwipeOn = settings.getInt("_isSwipeOn", 1);	
		_isDebugLevel_1 = settings.getInt("_isDebugLevel_1", 1);
		_isDebugLevel_2 = settings.getInt("_isDebugLevel_2", 1);
			
		// Debug Options
		if (_isDebugLevel_1 == 1) {
			isDebug = true;
		}
		if (_isDebugLevel_2 == 1) {
			isDeepDebug = true;
		}
		
		// Store Locale
		overrideLocale = settings.getInt("_overrideLocale", 0);	
	}
	
	public void saveStoredSettings () {
		
	    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
	    SharedPreferences.Editor editor = settings.edit();
	    editor.putInt("_setLanguage", _selectLanguage); 
	    editor.putInt("_isStartTab", _isStartTab);
	    editor.putInt("_isWirtschaftTab", _isWirtschaftTab);
	    editor.putInt("_isPolitikTab", _isPolitikTab);
	    editor.putInt("_isSportTab", _isSportTab);
	    editor.putInt("_isNetzweltTab", _isNetzweltTab);
	    editor.putInt("_isWissenschaftTab", _isWissenschaftTab);  
	    editor.putInt("_isPanoramaTab", _isPanoramaTab);  
	    editor.putInt("_isTickerTab", _isTickerTab);  
	    editor.putInt("_isRubrikenTab", _isRubrikenTab);  
	    
	    editor.putInt("_isSwipeOn", _isSwipeOn);
	    editor.putInt("_isDebugLevel_1", _isDebugLevel_1);
	    editor.putInt("_isDebugLevel_2", _isDebugLevel_2);
	    
	    editor.putInt("_overrideLocale", overrideLocale);
	    
	    editor.commit();
		
	}
	
   	public static void log(boolean deepLevel, String msg) {
		if (isDebug){ 
			if (isDeepDebug){ 
				Log.d("MattiDroid", msg); 
				}
			else
				if (deepLevel){
					Log.d("MattiDroid", msg); 
				}
		}
	}   	
   	
}
	 